from paddleocr import PaddleOCR
from os import getenv


def getImageInfo(file: str):
    model = getenv("OCR_MODEL") or '.'
    model = model.replace("\\", "/", -1)
    # set use_angle_cls as False, avoid the missing one row bug
    ocr = PaddleOCR(use_angle_cls=False, lang="ch",
                    rec_model_dir=f"{model}/rec/ch/ch_PP-OCRv4_rec_infer",
                    cls_model_dir=f"{model}/cls/ch_ppocr_mobile_v2.0_cls_infer",
                    det_model_dir=f"{model}/det/ch/ch_PP-OCRv4_det_infer")

    result = ocr.ocr(file, cls=True)
    return result[0]
